//
//  GXAddNewTableController.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/11/30.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXAddNewTableController.h"
#import "TableNumberManager.h"
@interface GXAddNewTableController ()
@property (weak, nonatomic) IBOutlet UITextField *tableNumberTF;
@property (weak, nonatomic) IBOutlet UITextField *pepleNumberTF;

@end

@implementation GXAddNewTableController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kGlobalbgColor;
    self.title = @"新增桌位";
    [self setUpNavigationBarRightItem];
}

- (void)setUpNavigationBarRightItem
{
    UIButton * rightButton =[UIButton setButtonTitleNormal:@"保存" buttonTintColor:[UIColor whiteColor]];
    [rightButton addTarget:self action:@selector(clickRightItemButton:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
}
- (void)clickRightItemButton:(UIButton *)saveBtn
{
    if (![self judgeTextFieldValue]) {
        return;
    }
    NSString * storeId = [AccountTool sharedAccountTool].account.sotres[@"storeId"];
    [TableNumberManager addTableNumberWithStoreID:storeId deskName:self.tableNumberTF.text peopleNum:self.pepleNumberTF.text success:^(id responseObject) {
        if (responseObject) {
            [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationAddTable object:nil];
        }
    } fail:^(id responseObject) {
    }];
    
    
}
- (BOOL)judgeTextFieldValue
{
    if ([NSString isBlankString:self.tableNumberTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入桌号"];
        return NO;
    }
    if (![NSString inputShouldNumber:self.tableNumberTF.text]) {
         [SVProgressHUD showErrorWithStatus:@"输入桌号应为数字"];
        return NO;
    }
    if ([NSString isBlankString:self.pepleNumberTF.text]) {
         [SVProgressHUD showErrorWithStatus:@"请输入可做人数"];
        return NO;
    }
    if (![NSString inputShouldNumber:self.pepleNumberTF.text]) {
         [SVProgressHUD showErrorWithStatus:@"输入可做人数应为数字"];
        return NO;
    }
    return YES;
}

@end
